package cn.com.wxd.amumu.search.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.com.wxd.amumu.search.ReturnContentType;
import cn.com.wxd.amumu.search.service.SearchService;

/**
 * Title:
 * Description:
 * <p>
 * Company: Amumu系统
 * Copyright: Copyright (c) 2017
 * All right reserved.
 * Created by WangXuDong on 2017/8/18.
 *
 * @author WangXuDong
 * @version 1.0
 */
@RestController
@RequestMapping("/search")
public class SearchCtl {

    private static final Logger log = LoggerFactory.getLogger(SearchCtl.class);
    private SearchService searchService = new SearchService();

    @RequestMapping(value = "/id", method = RequestMethod.GET)
    public AjaxResult searchId(String keyWord, int recordCount, int pageIndex){
        try {
            String[] result = searchService.search(keyWord,ReturnContentType.ID,recordCount,pageIndex);
            return AjaxResult.successResult(result);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return AjaxResult.errorResult(e.getMessage(),e);
        }

    }

    @RequestMapping(value = "/content", method = RequestMethod.GET)
    public AjaxResult searchContent(String keyWord, int maxCount){
        try {
            String[] result = searchService.search(keyWord,ReturnContentType.ID, maxCount);
            return AjaxResult.successResult(result);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return AjaxResult.errorResult(e.getMessage(),e);
        }
    }
}
